import {
  EntitySubscriberInterface,
  EventSubscriber,
  InsertEvent,
  UpdateEvent,
} from 'typeorm';

@EventSubscriber()
export class AppSubscriber implements EntitySubscriberInterface {
  beforeInsert(event: InsertEvent<any>) {
    // console.log(`BEFORE ENTITY INSERTED: `, event.entity);
    event.entity.createdAt = new Date().getTime();
    event.entity.updatedAt = new Date().getTime();
  }

  beforeUpdate(event: UpdateEvent<any>): void | Promise<any> {
    // console.log(`BEFORE ENTITY UPDATED: `, event.entity);
    event.entity.updatedAt = new Date().getTime();
  }
}
